<!--
 * @Description: file content
 * @Author: oooh
 * @Date: 2024-04-18 15:37:46
 * @LastEditors: hujunjie hujunjie@shudatech.cn
 * @LastEditTime: 2024-12-12 17:40:46
 * @FilePath: \Civil_Servant_Performance_PC\src\views\work\work-completion\index.vue
-->
<template>
  <div class="app-container">
    <el-row>
      <el-col>
        <!-- <el-select v-model="year" placeholder="请选择">
          <el-option v-for="item in yearOptions" :key="item.value" :label="item.label" :value="item.value"> </el-option>
        </el-select> -->
        <el-select
          v-model="queryParams.year"
          placeholder="请选择"
          @change="handleYearChange"
        >
          <el-option
            v-for="item in dict.type.biz_work_year_list"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
        <el-select
          v-model="queryParams.quarter"
          placeholder="请选择"
          class="ml-10"
          @change="handleQuarterChange"
        >
          <el-option
            v-for="item in quarterOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-col>
    </el-row>
    <div class="text-banner">
      <span>重点工作（共 {{ keyWorkTotal }} 条）</span>
      <el-button
        size="mini"
        type="primary"
        circle
        icon="el-icon-refresh"
        plain
        @click="getKeyWorkList"
      />
    </div>
    <div></div>
    <div v-loading="keyWorkLoading">
      <div v-for="keyWork in keyWork" :key="keyWork.month">
        <div class="month-title">
          <p>
            <span class="month-mark-first">{{ keyWork.month }}</span
            >月份重点工作
            <span class="ml-20">共计</span>
            <span class="month-mark-second">{{ keyWorkMaxScore }}</span>
            分， 已分配<span class="month-mark-second">{{ keyWork.score }}</span
            >分， 剩余可分配<span class="month-mark-second">{{
              keyWorkMaxScore - keyWork.score
            }}</span
            >分
          </p>
        </div>
        <div>
          <!-- 上传提示 -->
          <div class="el-upload__tip">
            <p>
              <b style="color: #f56c6c">*完成材料：</b>大小不超过
              <b style="color: #f56c6c">{{ fileSize }}MB</b> 格式为
              <b style="color: #f56c6c">{{ fileType.join("/") }}</b
              >的文件（不超过<b style="color: #f56c6c">{{ limit }}</b
              >项）
            </p>
          </div>
          <el-table :data="keyWork.list" border style="width: 100%" ref="table">
            <el-table-column label="序号" type="index" align="center">
              <template slot-scope="scope">
                <span>{{ scope.$index + 1 }}</span>
              </template>
            </el-table-column>
            <el-table-column
              prop="normName"
              label="指标名称"
              width="180"
              align="center"
            >
            </el-table-column>
            <!-- <el-table-column prop="workNatureDict" label="工作性质" width="180" align="center">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.biz_work_nature" :value="scope.row.workNatureDict" />
              </template>
            </el-table-column> -->
            <el-table-column
              prop="workContent"
              label="内容及方式"
              min-width="180"
              align="center"
            >
              <template slot-scope="scope">
                <div class="pre-wrap align-left">
                  {{ scope.row.workContent || "-" }}
                </div>
              </template>
            </el-table-column>
            <el-table-column
              prop="planScore"
              label="分值"
              width="80"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="workCompletionSituationDict"
              label="完成情况"
              min-width="130"
              align="center"
            >
              <template slot-scope="scope">
                <el-select
                  v-show="!checkWorkPlanDisabled(scope.row.workReportMark)"
                  v-model="scope.row.workCompletionSituationDict"
                  placeholder="完成情况"
                >
                  <el-option
                    v-for="item in dict.type.biz_dept_important_work_completion"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
                <dict-tag
                  v-show="checkWorkPlanDisabled(scope.row.workReportMark)"
                  :options="dict.type.biz_dept_important_work_completion"
                  :value="scope.row.workCompletionSituationDict"
                />
              </template>
            </el-table-column>
            <el-table-column
              prop="remarks"
              label="备注"
              min-width="200"
              align="center"
            >
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.remarks"
                  type="textarea"
                  placeholder="输入备注内容"
                  :rows="1"
                  :autosize="{ minRows: 1, maxRows: 5 }"
                  v-show="!checkWorkPlanDisabled(scope.row.workReportMark)"
                ></el-input>
                <span
                  v-show="checkWorkPlanDisabled(scope.row.workReportMark)"
                  >{{ scope.row.remarks || "-" }}</span
                >
              </template>
            </el-table-column>
            <el-table-column
              prop="selfScore"
              label="自评得分"
              width="130"
              align="center"
            >
              <template slot-scope="scope">
                <el-input-number
                  v-model="scope.row.selfScore"
                  placeholder="自评分"
                  controls-position="right"
                  :min="0"
                  v-show="!checkWorkPlanDisabled(scope.row.workReportMark)"
                ></el-input-number>
                <span
                  v-show="checkWorkPlanDisabled(scope.row.workReportMark)"
                  >{{
                    !isNaN(scope.row.selfScore) ? scope.row.selfScore : "-"
                  }}</span
                >
              </template>
            </el-table-column>
            <el-table-column
              prop="workCompletionMaterialUrls"
              label="完成材料"
              min-width="180"
              align="center"
            >
              <template slot-scope="scope">
                <FileUpload
                  v-show="!checkWorkPlanDisabled(scope.row.workReportMark)"
                  v-model="scope.row.workCompletionMaterialUrls"
                  :isShowTip="false"
                  :fileType="fileType"
                  @input="$refs['table'].doLayout()"
                ></FileUpload>
                <div v-show="checkWorkPlanDisabled(scope.row.workReportMark)">
                  <div v-if="scope.row.workCompletionMaterialUrls">
                    <el-tooltip
                      v-for="(
                        url, index
                      ) in scope.row.workCompletionMaterialUrls.split(',')"
                      :key="index"
                      effect="dark"
                      :content="formatFileUrl(url)['name']"
                      placement="top-start"
                    >
                      <el-button
                        type="text"
                        @click="handlePreviewFile(url)"
                        class="file-preview-btn"
                      >
                        {{ formatFileUrl(url)["name"] }}
                      </el-button>
                    </el-tooltip>
                  </div>
                  <span v-else>-</span>
                </div>
              </template>
            </el-table-column>
            <el-table-column
              prop="workCompletionDate"
              label="完成日期"
              width="160"
              align="center"
            >
              <template slot-scope="scope">
                <el-date-picker
                  v-model="scope.row.workCompletionDate"
                  type="date"
                  value-format="yyyy-MM-dd"
                  placeholder="选择日期"
                  v-show="!checkWorkPlanDisabled(scope.row.workReportMark)"
                  :clearable="false"
                >
                </el-date-picker>
                <span
                  v-show="checkWorkPlanDisabled(scope.row.workReportMark)"
                  >{{ scope.row.workCompletionDate }}</span
                >
              </template>
            </el-table-column>
            <el-table-column
              prop="name"
              label="操作"
              align="center"
              width="140"
              fixed="right"
            >
              <template slot-scope="scope">
                <el-button
                  type="text"
                  v-show="
                    checkBtnVisible(
                      'revocation',
                      scope.row.reportAuditStatusDict
                    )
                  "
                  class="color-warning"
                  size="mini"
                  @click.stop="handleWorkPlanRevocation(scope.row, 'keyWork')"
                  v-hasPermi="['work:work-completion:revocation']"
                  :disabled="!isWorkEdit"
                >
                  [审核中]点击撤回
                </el-button>
                <ApprovalLog
                  :biz-id="scope.row.workScoreId"
                  v-show="
                    checkBtnVisible('approval', scope.row.reportAuditStatusDict)
                  "
                >
                  <el-button type="text" class="color-warning" size="mini">
                    [审核中]
                  </el-button>
                </ApprovalLog>
                <ApprovalLog
                  :biz-id="scope.row.workScoreId"
                  v-show="
                    checkBtnVisible('finish', scope.row.reportAuditStatusDict)
                  "
                >
                  <el-button
                    type="text"
                    size="mini"
                    class="color-success"
                    icon="el-icon-check"
                    >[审核通过]</el-button
                  >
                </ApprovalLog>

                <ApprovalLog
                  :biz-id="scope.row.workScoreId"
                  v-show="
                    checkBtnVisible('resubmit', scope.row.reportAuditStatusDict)
                  "
                >
                  <el-button
                    type="text"
                    icon="el-icon-warning-outline"
                    size="mini"
                    @click.stop="
                      handleWorkPlanSaveOrSubmit(scope.row, 'keyWork', 'submit')
                    "
                    class="color-danger"
                    v-hasPermi="['work:work-completion:submit']"
                    :disabled="!isWorkEdit"
                  >
                    [被退回]重新提交
                  </el-button>
                </ApprovalLog>
                <el-button
                  type="text"
                  v-show="
                    checkBtnVisible(
                      'save',
                      scope.row.reportAuditStatusDict,
                      scope.row.workReportMark
                    )
                  "
                  size="mini"
                  @click.stop="
                    handleWorkPlanSaveOrSubmit(scope.row, 'keyWork', 'save')
                  "
                  v-hasPermi="['work:work-completion:save']"
                  :disabled="!isWorkEdit"
                >
                  保存
                </el-button>

                <el-button
                  type="text"
                  v-show="
                    checkBtnVisible(
                      'submit',
                      scope.row.reportAuditStatusDict,
                      scope.row.workReportMark
                    )
                  "
                  size="mini"
                  @click.stop="
                    handleWorkPlanSaveOrSubmit(scope.row, 'keyWork', 'submit')
                  "
                  v-hasPermi="['work:work-completion:submit']"
                  :disabled="!isWorkEdit"
                >
                  提交
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
    </div>

    <div class="text-banner mt-45">
      <span>中心工作（共 {{ centerWorkTotal }} 条）</span>
      <el-button
        size="mini"
        type="primary"
        circle
        icon="el-icon-refresh"
        plain
        @click="getCenterWorkList"
      />
    </div>
    <div v-loading="centerWorkLoading">
      <div v-for="work in centerWorkList" :key="work.quarter">
        <div class="month-title">
          <p>
            <span class="month-mark-first">{{ work.quarter }}</span>
            季度中心工作
            <!-- <span class="ml-20">共计</span>
            <span class="month-mark-second">{{ centerWorkMaxScore }}</span> 分， 已分配<span class="month-mark-second">
              {{ work.score }}
            </span>
            分， 剩余<span class="month-mark-second">{{ centerWorkMaxScore - work.score }}</span>
            分 -->
          </p>
        </div>
        <div>
          <el-table :data="work.list" border style="width: 100%">
            <el-table-column label="序号" type="index" align="center">
              <template slot-scope="scope">
                <span>{{ scope.$index + 1 }}</span>
              </template>
            </el-table-column>
            <el-table-column
              prop="normName"
              label="指标名称"
              width="180"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="workContent"
              label="指标打分说明"
              min-width="180"
              align="center"
            >
              <template slot-scope="scope">
                <div class="pre-wrap align-left">
                  {{ scope.row.workContent || "" }}
                </div>
              </template>
            </el-table-column>
            <el-table-column
              prop="deptName"
              label="责任单位"
              align="center"
              show-overflow-tooltip
            >
              <template slot-scope="scope">
                <span>{{ scope.row.deptName }}</span>
              </template>
            </el-table-column>
            <el-table-column
              prop="planScore"
              label="分值"
              width="80"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="workCompletionSituation"
              label="完成情况"
              min-width="180"
              align="center"
            >
              <template slot-scope="scope">
                <span>{{ scope.row.workCompletionSituation || "-" }}</span>
              </template>
            </el-table-column>
            <el-table-column
              prop="selfScore"
              label="自评得分"
              width="80"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="workCompletionMaterialUrls"
              label="完成材料"
              min-width="180"
              align="center"
            >
              <template slot-scope="scope">
                <div v-if="scope.row.workCompletionMaterialUrls">
                  <el-tooltip
                    v-for="(
                      url, index
                    ) in scope.row.workCompletionMaterialUrls.split(',')"
                    :key="index"
                    effect="dark"
                    :content="formatFileUrl(url)['name']"
                    placement="top-start"
                  >
                    <el-button
                      type="text"
                      @click="handlePreviewFile(url)"
                      size="mini"
                      class="file-preview-btn"
                    >
                      {{ formatFileUrl(url)["name"] }}
                    </el-button>
                  </el-tooltip>
                </div>
                <span v-else>-</span>
              </template>
            </el-table-column>
            <el-table-column
              prop="workCompletionDate"
              label="完成日期"
              width="130"
              align="center"
            >
              <template slot-scope="scope">
                <span>{{ scope.row.workCompletionDate || "-" }}</span>
              </template>
            </el-table-column>
            <el-table-column
              prop="demandCompletionDate"
              label="纳入进度管理"
              width="145"
              align="center"
            >
              <template slot-scope="scope">
                <span>{{
                  scope.row.demandCompletionDate
                    ? scope.row.demandCompletionDate + " 前完成":"-"
                }}</span>
              </template>
            </el-table-column>
            <!-- <el-table-column prop="remarks" label="备注" min-width="150" align="center"> </el-table-column> -->
            <el-table-column
              prop="name"
              label="操作"
              align="center"
              width="140"
              fixed="right"
            >
              <template slot-scope="scope">
                <div v-if="scope.row.createMark">
                  <el-button
                    type="text"
                    v-show="
                      checkBtnVisible(
                        'revocation',
                        scope.row.reportAuditStatusDict
                      )
                    "
                    class="color-warning"
                    size="mini"
                    @click.stop="
                      handleWorkPlanRevocation(scope.row, 'centerWork')
                    "
                    v-hasPermi="['work:work-completion:revocation']"
                    :disabled="!isWorkEdit"
                  >
                    [审核中]点击撤回
                  </el-button>
                  <ApprovalLog
                    :biz-id="scope.row.workScoreId"
                    v-show="
                      checkBtnVisible(
                        'approval',
                        scope.row.reportAuditStatusDict
                      )
                    "
                  >
                    <el-button type="text" class="color-warning" size="mini">
                      [审核中]
                    </el-button>
                  </ApprovalLog>
                  <ApprovalLog
                    :biz-id="scope.row.workScoreId"
                    v-show="
                      checkBtnVisible('finish', scope.row.reportAuditStatusDict)
                    "
                  >
                    <el-button
                      type="text"
                      size="mini"
                      class="color-success"
                      icon="el-icon-check"
                      @click="handleCenterWorkCompletion(scope.row, 'view')"
                      >[审核通过]</el-button
                    >
                  </ApprovalLog>

                  <ApprovalLog
                    :biz-id="scope.row.workScoreId"
                    v-show="
                      checkBtnVisible(
                        'resubmit',
                        scope.row.reportAuditStatusDict
                      )
                    "
                  >
                    <el-button
                      type="text"
                      icon="el-icon-warning-outline"
                      size="mini"
                      @click.stop="
                        handleWorkPlanSaveOrSubmit(
                          scope.row,
                          'centerWork',
                          'submit'
                        )
                      "
                      class="color-danger"
                      v-hasPermi="['work:work-completion:submit']"
                      :disabled="!isWorkEdit"
                    >
                      [被退回]重新提交
                    </el-button>
                  </ApprovalLog>

                  <el-button
                    type="text"
                    size="mini"
                    v-show="
                      checkBtnVisible(
                        'save',
                        scope.row.reportAuditStatusDict,
                        scope.row.workReportMark
                      )
                    "
                    @click="handleCenterWorkCompletion(scope.row, 'edit')"
                    :disabled="!isWorkEdit"
                    >工作评分</el-button
                  >

                  <el-button
                    type="text"
                    v-show="
                      checkBtnVisible(
                        'submit',
                        scope.row.reportAuditStatusDict,
                        scope.row.workReportMark
                      )
                    "
                    size="mini"
                    @click.stop="
                      handleWorkPlanSaveOrSubmit(
                        scope.row,
                        'centerWork',
                        'submit'
                      )
                    "
                    v-hasPermi="['work:work-completion:submit']"
                    :disabled="!isWorkEdit"
                  >
                    提交
                  </el-button>
                </div>
                <div v-else>
                  <el-button
                    type="text"
                    v-if="scope.row.workReportMark"
                    size="mini"
                    @click="handleCenterWorkCompletion(scope.row, 'view')"
                    >[纪实详情]</el-button
                  >
                  <el-button
                    type="text"
                    v-else
                    size="mini"
                    disabled
                    icon="el-icon-document-remove"
                    >[暂未纪实]</el-button
                  >
                </div>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
    </div>
    <FilePreview
      :visible.sync="filePreviewVisible"
      :file="previewFile"
    ></FilePreview>
    <CenterWorkCompletion
      :visible.sync="centerWorkVisible"
      :work="centerWork"
      :operation="centerWorkOperation"
      @success="getCenterWorkList"
    ></CenterWorkCompletion>
  </div>
</template>

<script>
import { workSaveOrSubmit, revocation } from "@/api/work/work-completion";
import { list as listPlan } from "@/api/work/work-plan";
import {
  quarterFormat,
  quarterToMonth,
  checkQuarterWorkEdit,
} from "@/utils/quarter.js";
import { getDicts } from "@/api/system/dict/data.js";
import FilePreview from "@/components/FilePreview";
import FileUpload from "@/components/FileUpload";
import { mapGetters } from "vuex";
import CenterWorkCompletion from "@/views/work/work-completion/components/CenterWorkCompletion";
import dayjs from "dayjs";
import { mixins } from "@/mixins";
import ApprovalLog from "@/components/ApprovalLog";
export default {
  name: "work-completion",
  mixins: [mixins],
  props: {},
  dicts: [
    "biz_work_year_list",
    "biz_work_nature",
    "biz_work_score_type",
    "biz_dept_important_work_completion",
  ],
  components: { FileUpload, FilePreview, CenterWorkCompletion, ApprovalLog },
  data() {
    return {
      isWorkEdit: false,
      filePreviewVisible: false,
      previewFile: {},
      // 重点工作映射项
      keyWorkMapping: {
        workCompletionSituationDict: "完成情况",
        selfScore: "自评得分",
        workCompletionDate: "完成日期",
      },
      keyWorkItem: {
        selfScore: undefined,
        workCompletionMaterialUrls: undefined,
        workCompletionDate: dayjs().format("YYYY-MM-DD"),
        workCompletionSituationDict: undefined,
        remarks: undefined,
      },
      keyWorkMaxCount: 0,
      keyWorkTotal: 0,
      keyWork: [],
      keyWorkMaxScore: 0, // 重点工作最大分值
      keyWorkLoading: false,
      // 中心工作映射项
      centerWorkMapping: {
        workCompletionSituation: "完成情况",
        selfScore: "自评得分",
        workCompletionDate: "完成日期",
      },
      centerWorkItem: {
        selfScore: undefined,
        workCompletionMaterialUrls: undefined,
        workCompletionDate: dayjs().format("YYYY-MM-DD"),
        workCompletionSituation: undefined,
      },
      centerWorkTotal: 0,
      centerWorkList: [],
      centerWorkMaxScore: 0, // 中心工作最大分值
      centerWorkLoading: false,
      centerWork: {},
      centerWorkVisible: false,
      centerWorkOperation: "view",
      quarterOptions: [],
      queryParams: {
        year: "",
        quarter: "",
        workAuditStatusDict: "SHTG",
      },
    };
  },
  computed: {
    ...mapGetters(["dept"]),
  },
  watch: {
    dept: {
      deep: true,
      immediate: true,
      handler(val) {
        this.centerWorkItem.deptName = this.dept?.deptName;
      },
    },
  },
  created() {
    this.getWorkScore();
    this.handleYearChange(new Date().getFullYear());
  },
  methods: {
    // 工作计划撤回
    handleWorkPlanRevocation(raw, workType) {
      revocation({ id: raw.id }).then((res) => {
        this.$modal.msgSuccess("已撤回");
        if (workType === "keyWork") {
          this.getKeyWorkList();
        } else if (workType === "centerWork") {
          this.getCenterWorkList();
        } else {
          getList();
        }
      });
    },
    // 中心工作评分
    handleCenterWorkCompletion(raw, operation) {
      this.centerWork = raw;
      this.centerWorkOperation = operation;
      this.centerWorkVisible = true;
    },
    // 预览文件
    handlePreviewFile(url) {
      let fileItem = this.formatFileUrl(url);
      this.previewFile = { url, ...fileItem };
      this.filePreviewVisible = true;
    },
    // 功能类型、审核状态、提交状态
    checkBtnVisible(type, audit, submit) {
      switch (type) {
        case "revocation":
          // 撤回
          return audit === "DSH";
        case "submit":
          // 提交
          return !submit && audit !== "SHBTG";
        case "save":
        case "remove":
          // 保存 && 删除
          return !submit;
        case "resubmit":
          // 退回重新提交
          return audit === "SHBTG";
        case "finish":
          // 审核通过
          return audit === "SHTG";
        case "approval":
          // 审核中（不可撤回）
          return audit === "SHZ";
        default:
          break;
      }
    },
    // 校验工作计划表单字段是否可填
    checkWorkPlanDisabled(audit) {
      return audit;
    },
    // 工作计划保存或提交校验
    handleWorkPlanSaveOrSubmitCheck(raw, workType) {
      let mapping = {};
      if (workType === "keyWork") {
        mapping = this.keyWorkMapping;
      } else if (workType === "centerWork") {
        mapping = this.centerWorkMapping;
      }
      for (let key of Object.keys(mapping)) {
        if ((raw[key] == "" || raw[key] == null) && key !== "selfScore") {
          this.$message.error(`操作失败，【${mapping[key]}】 不能为空！`);
          return;
        }
      }

      let mustItem = {};
      let params = { id: raw.id };
      // 根据工作类型填充对应参数
      if (workType === "keyWork") {
        for (let key of Object.keys(this.keyWorkItem)) {
          mustItem[key] = raw[key];
        }
        params = { ...params, month: raw.month, ...mustItem };
      } else if (workType === "centerWork") {
        for (let key of Object.keys(this.centerWorkItem)) {
          mustItem[key] = raw[key];
        }
        params = { ...params, ...mustItem };
      }
      return params;
    },
    // 工作计划保存或提交
    async handleWorkPlanSaveOrSubmit(raw, workType, operationType = "save") {
      let params = await this.handleWorkPlanSaveOrSubmitCheck(
        raw,
        workType,
        operationType
      );
      if (!params) return;
      params.workReportMark = false;

      if (operationType === "submit") {
        params.workReportMark = true;
      }

      // 保存或提交工作纪实
      await workSaveOrSubmit(params).then((res) => {
        if (operationType === "save") {
          this.$modal.msgSuccess("工作纪实已保存");
        } else if (operationType === "submit") {
          this.$modal.msgSuccess("工作纪实已提交");
        }
      });

      if (workType === "keyWork") {
        this.getKeyWorkList();
      } else if (workType === "centerWork") {
        this.getCenterWorkList();
      } else {
        getList();
      }
    },
    // 中心工作已使用分值
    centerWorkUsedScore(quarter) {
      const index = this.centerWorkList.findIndex(
        (item) => item.quarter == quarter
      );
      const sum = this.centerWorkList[index].list.reduce((prev, curr) => {
        if (curr.planScore) {
          return prev + parseInt(curr.planScore);
        } else {
          return prev;
        }
      }, 0);
      this.$set(this.centerWorkList[index], "score", sum);
    },
    // 重点工作已使用分值
    keyWorkUsedScore(month) {
      const index = this.keyWork.findIndex((item) => item.month == month);
      const sum = this.keyWork[index].list.reduce((prev, curr) => {
        if (curr.planScore) {
          return prev + parseInt(curr.planScore);
        } else {
          return prev;
        }
      }, 0);
      this.$set(this.keyWork[index], "score", sum);
    },
    // 获取工作分数限制
    getWorkScore() {
      getDicts("biz_dept_norm_config").then((res) => {
        let { data } = res;
        this.keyWorkMaxScore = data.find(
          (item) => item.dictValue === "ZDGZ"
        )?.remark;
        this.centerWorkMaxScore = data.find(
          (item) => item.dictValue === "ZXGZ"
        )?.remark;
      });
    },
    // 年度选择
    handleYearChange(year) {
      this.queryParams.year = year;
      // 获取当前季度、季度列表（往年默认第一季度）
      let { quarter, quarterList } = quarterFormat(year);
      this.quarterOptions = quarterList;
      this.handleQuarterChange(quarter);
    },
    // 季度选择
    handleQuarterChange(quarter) {
      this.queryParams.quarter = quarter;
      // 获取季度对应月份
      this.keyWork = quarterToMonth(quarter).map((month) => {
        return { month, score: 0, list: [] };
      });
      checkQuarterWorkEdit({ year: this.queryParams.year, quarter }).then(
        (res) => {
          this.isWorkEdit = res;
        }
      );
      this.getList();
    },
    getList() {
      this.getKeyWorkList();
      this.getCenterWorkList();
    },
    // 中心工作列表
    getCenterWorkList() {
      this.centerWorkLoading = true;
      listPlan({ ...this.queryParams, workType: "ZXGZ" })
        .then((res) => {
          this.centerWorkLoading = false;
          let { rows, total } = res;
          this.centerWorkTotal = total;
          this.centerWorkList = [
            { score: 0, quarter: this.queryParams.quarter, list: rows },
          ];
          this.centerWorkUsedScore(this.queryParams.quarter);
        })
        .catch((err) => (this.centerWorkLoading = false));
    },
    // 重点工作列表
    getKeyWorkList() {
      this.keyWorkLoading = true;
      listPlan({ ...this.queryParams, workType: "ZDGZ" })
        .then((res) => {
          let { rows, total } = res;
          this.keyWorkTotal = total;
          // 筛选季度对应月份数据
          this.keyWork.forEach((item, index) => {
            this.keyWorkLoading = false;
            this.keyWork[index].list = rows.filter(
              (work) => item.month == work.month
            );
            // 获取到列表数据手动计算值情况
            this.keyWorkUsedScore(this.keyWork[index].month);
          });
        })
        .catch((err) => (this.keyWorkLoading = false));
    },
  },
};
</script>

<style lang="scss" scoped>
@import url("~@/assets/styles/work.scss");
::v-deep .el-date-editor.el-input,
.el-date-editor.el-input__inner {
  width: auto;
}

::v-deep .el-input-number--medium {
  width: auto;
}

::v-deep .el-button [class*="el-icon-"] + span {
  margin-left: 0;
}

.file-preview-btn {
  width: 100%;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  margin-left: 0;
  padding: 0;
}
</style>
